#include <pthread.h>
#include <stdio.h>

static pthread_mutex_t mutex;
static volatile int cnt = 0;
static const int MAX = 10000;

void *display(void *arg)
{
    int j = 10000;
    while(j--) {
        pthread_mutex_lock(&mutex);
        cnt++;
        pthread_mutex_unlock(&mutex);
    }
    arg = arg;
    return 0;
}

int main(int argc, char const* argv[])
{
    const int NUM = 2000;
    pthread_t thread[NUM];
    int i = 0;

    argc = argc;
    argv = argv;

    for (i = 0; i<NUM; ++i) {
        pthread_create(&thread[i], NULL, display, NULL);
    }

    for (i = 0; i<NUM; ++i) {
        pthread_join(thread[i], NULL);
    }

    printf("i=%d\n", cnt);

	return 0;
}
